1 package net.sourceforge.selfesteem.applet;
2
3 /*
4 * %W% %E%
5 *
6 * Copyright 1997, 1998 by Sun Microsystems, Inc.,
7 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
8 * All rights reserved.
9 *
10 * This software is the confidential and proprietary information
11 * of Sun Microsystems, Inc. ("Confidential Information"). You
12 * shall not disclose such Confidential Information and shall use
13 * it only in accordance with the terms of the license agreement
14 * you entered into with Sun.
15 */
16
17 import javax.swing.*;
18 import javax.swing.event.TreeExpansionEvent;
19 import javax.swing.event.TreeExpansionListener;
20 import javax.swing.table.AbstractTableModel;
21 import javax.swing.tree.TreePath;
22
23 public class TreeTableModelAdapter extends AbstractTableModel {
24 JTree tree;
25
26 public TreeTableModelAdapter(JTree tree) {
27 this.tree = tree;
28
29 tree.addTreeExpansionListener(new TreeExpansionListener() {
30 // Don't use fireTableRowsInserted() here;
31 // the selection model would get updated twice.
32 public void treeExpanded(TreeExpansionEvent event) {
33 fireTableDataChanged();
34 }
35
36 public void treeCollapsed(TreeExpansionEvent event) {
37 fireTableDataChanged();
38 }
39 });
40 }
41
42 // Wrappers, implementing TableModel interface.
43
44 public int getColumnCount() {
45 return 2;
46 }
47
48 public String getColumnName(int column) {
49 return "foo";
50 }
51
52 public Class getColumnClass(int column) {
53 return column == 0 ? TreeTableModel.class : Integer.class;
54 }
55
56 public int getRowCount() {
57 return tree.getRowCount();
58 }
59
60 protected Object nodeForRow(int row) {
61 TreePath treePath = tree.getPathForRow(row);
62 return treePath.getLastPathComponent();
63 }
64
65 public Object getValueAt(int row, int column) {
66 MyTreeNode mynode = (MyTreeNode) nodeForRow(row);
67 try {
68 switch (column) {
69 case 0:
70 return mynode.getUserObject();
71 case 1:
72 return mynode.getPercent();
73 }
74 } catch (SecurityException se) {
75 }
76
77 return null;
78 }
79
80 public boolean isCellEditable(int row, int column) {
81 return column == 0;
82 }
83
84 public void setValueAt(Object value, int row, int column) {
85 }
86 }
This page was automatically generated by Maven